package com.feihao.zhou.demo03callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableDemoTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建MyCallable对象：
        MyCallable mc = new MyCallable();

        //创建FutureTask中间媒介：
        //可以获取线程执行完毕后的结果，可以作为参数传递给Thread对象
        FutureTask<String> ft = new FutureTask<String>(mc);

        //创建线程对象：
        Thread t1 = new Thread(ft);
        Thread t2 = new Thread(ft);

        //开启线程：
        t1.start();
        t2.start();

        //获取线程返回结果：
        String s = ft.get();
        System.out.println(s);
    }
}
